package hai.com.android_test.ui;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.LinearLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import hai.com.android_test.R;
import hai.com.android_test.ui.fragment.VpFragment;

public class NestScrollTest extends AppCompatActivity {

//    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tabLayout)
    TabLayout tabLayout;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    String[] titles;
    List<Fragment> list = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nestscroll);
        ButterKnife.bind(this);
//        toolbar.setTitle("nestscrolltest");
//        setSupportActionBar(toolbar);
        titles = new String[]{"one", "two", "three", "four"};
        for (int i = 0; i < titles.length; i++) {
            list.add(VpFragment.newInstance(titles[i]));
            tabLayout.addTab(tabLayout.newTab().setText(titles[i]));
        }
        FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return list.get(position);
            }

            @Override
            public int getCount() {
                return titles.length;
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        };
        viewpager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewpager);
        LinearLayout childAt = (LinearLayout) tabLayout.getChildAt(0);
        childAt.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        childAt.setDividerDrawable(getResources().getDrawable(R.drawable.devider_tablayout));
    }


}
